<?php
class apiMod extends commonMod {
	public function __construct() {
		parent::__construct ();
	}
	public function login() {
		$data_return_array = array ();
		
		if (empty ( $_POST ['tel'] ) || empty ( $_POST ['pwd'] )) {
			$data_return_array ['result'] = "0";
			$data_return_array ['msg'] = "缺少参数";
			$data_return_array ['data'] = "";
			$data_return = $this->JSON ( $data_return_array ); //把返回数据转换成json格式供客户端解析
			die ( $data_return );//输出数据
			exit ();
		}
		$_POST = in ( $_POST );
		$user_info = $this->model->table ( "member" )->where ( " tel = '" . $_POST ['tel'] . "' " )->find ();
		
		if (empty ( $user_info )) {
			$data_return_array ['result'] = "0";
			$data_return_array ['msg'] = "无此用户";
			$data_return_array ['data'] = "";
			$data_return = $this->JSON ( $data_return_array );
			die ( $data_return );
			exit ();
		}
		
		if ($user_info['pwd'] != md5($_POST['pwd'])){
			$data_return_array ['result'] = "0";
			$data_return_array ['msg'] = "密码错误";
			$data_return_array ['data'] = "";
			$data_return = $this->JSON ( $data_return_array );
			die ( $data_return );
			exit ();
		}
		$tmp = array();
		$tmp['uid'] = $user_info['id'];
		$tmp['user_name'] = $user_info['user_name'];
		$tmp['token'] = $user_info['token'];
		$data_return_array ['result'] = "1";
		$data_return_array ['msg'] = "";
		$data_return_array ['data'] = $user_info;
		$data_return = $this->JSON ( $data_return_array );
		die ( $data_return );
		exit ();
		
		
		
	}
}